﻿using Microsoft.EntityFrameworkCore;
using PlatformUW.Contracts;
using PlatformUW.Entities;

namespace PlatformUW.EntityFramework.Repositories
{
    public class CharacterRepository : BaseRepository<Characters>, ICharacterRepository
    {
        public CharacterRepository(PlatformDBContext repositoryContext) : base(repositoryContext)
        {
        }

        public async Task<List<Characters>> GetAllCharactersAsync()
        {
            return await Task.FromResult(respositoryContext
                .Set<Characters>()
                .OrderBy(c => c.DateCreated)
                .ToList());
        }

        public Task<Characters> GetCharactersByIDAsync(Guid id)
        {
            return Task.FromResult(FindAsync(e => e.Id == id).Result.FirstOrDefault());
        }

        public Task<Characters> GetCharacterWithPlayerByIdAsync(Guid id)
        {
            return Task.FromResult(respositoryContext.Set<Characters>()
                .Where(a => a.Id == id)
                .Include(a => a.player).FirstOrDefault());
        }
    }
}
